"""
按周期计算收益率，简单方法
"""
class zone_state:
    def __init__(self,split_lines=[],split_states=None):
        self.split_lines=split_lines
        if split_states   is None:
            self.split_states=list(range(len(split_lines)+1))
        else:
            self.split_states=split_states
            if len(self.split_states)!=len(self.split_lines)+1:
                raise Exception("算子错误zone_state,split_states must be len(split_lines)+1")
    def oncalc(self,d,timekey=None):
        rst=None
        if d is not None:
            for i in self.split_lines:
                if d<=i:
                    rst=self.split_states[self.split_lines.index(i)]
                    break
            if d>i:
                rst=self.split_states[-1]
        return rst
